package com.bw.base.mvvm

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.bw.base.entity.Res
import kotlinx.coroutines.launch

open class BaseViewModel :ViewModel(){
    fun<T> httpResult(s:suspend ()-> Res<T>,success:(T)->Unit){
        viewModelScope.launch {
      try {
          val invoke = s.invoke()
          if (invoke.code==200){
              success(invoke.data)
          }else{
              Log.i("park",invoke.message)
          }
      }catch (e:Exception){
          Log.i("park",e.message.toString())
          e.printStackTrace()
      }

        }
    }
}